package com.liao.furns.web; /**
 * @author lzp
 * @version 1.0
 * lzpnb!
 */

import com.liao.furns.pojo.Furn;
import com.liao.furns.pojo.Page;
import com.liao.furns.service.FurnService;
import com.liao.furns.service.impl.FurnServiceImpl;
import com.liao.furns.utils.DataUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "CustomerFurnServlet", value = "/CustomerFurnServlet")
public class CustomerFurnServlet extends BasicServlet {
    private FurnService furnService = new FurnServiceImpl();
    public void page(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNo = DataUtils.parseInt(request.getParameter("pageNo"), 1);
        int pageSize = DataUtils.parseInt(request.getParameter("pageSize"), Page.PAGE_SIZE);
        Page<Furn> page = furnService.page(pageNo,pageSize);
//        System.out.println(page);
        request.setAttribute("page",page);
        request.getRequestDispatcher("/views/customer/index.jsp").forward(request,response);
    }

    public void pageByName(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNo = DataUtils.parseInt(request.getParameter("pageNo"), 1);
        int pageSize = DataUtils.parseInt(request.getParameter("pageSize"), Page.PAGE_SIZE);
        String name = request.getParameter("name");
        if(name == null){
            name = "";
        }
        Page<Furn> page = furnService.pageByName(pageNo,pageSize,name);
        StringBuffer url = new StringBuffer("CustomerFurnServlet?action=pageByName");
        if(!"".equals(name)){
            url.append("&name=").append(name);
        }
        page.setUrl(url.toString());
//        System.out.println(page);
        request.setAttribute("page",page);
        request.getRequestDispatcher("/views/customer/index.jsp").forward(request,response);
    }
}
